package com.asl.website.solution.domain;

/**
 * @author 482944566@qq.com
 * @version 1.0
 * @date 2025-05-21
 */

import com.asl.common.utils.StringUtils;
import com.asl.website.common.Language;

import java.util.List;
import java.util.stream.Collectors;

/**
 * 运输解决方案响应DTO
 */
public class TransportSolutionDTO {
    private List<SolutionItem> solutions;
    private String language;

    // 构造方法
    public TransportSolutionDTO(List<BizTransportSolution> solutions, String language) {
        this.language = language;
        this.solutions = solutions.stream()
                .map(solution -> new SolutionItem(solution, language))
                .collect(Collectors.toList());
    }

    // 内部静态类 - 单个解决方案项
    public static class SolutionItem {
        private Long id;
        private String title;
        private String description;
        private String iconUrl;

        public SolutionItem(BizTransportSolution solution, String language) {
            this.id = solution.getId();
            this.iconUrl = solution.getIconUrl();


            switch (Language.fromCode(language)) {
                case EN_US:
                    this.title = StringUtils.firstNonBlank(solution.getTitleEn(), solution.getTitleZh());
                    this.description = StringUtils.firstNonBlank(solution.getDescriptionEn(), solution.getDescriptionZh());
                    break;
                case DE_DE:
                    this.title = StringUtils.firstNonBlank(solution.getTitleDe(), solution.getTitleZh());
                    this.description = StringUtils.firstNonBlank(solution.getDescriptionDe(), solution.getDescriptionZh());
                    break;
                default: // 默认中文
                    this.title = solution.getTitleZh();
                    this.description = solution.getDescriptionZh();
            }
        }

        // getters
        public Long getId() {
            return id;
        }

        public String getTitle() {
            return title;
        }

        public String getDescription() {
            return description;
        }

        public String getIconUrl() {
            return iconUrl;
        }


    }

    // getters
    public List<SolutionItem> getSolutions() {
        return solutions;
    }

    public String getLanguage() {
        return language;
    }
}